import "reflect-metadata";

// 1. 对象
let obj = {
  username: "北银",
  age: 23,
  info() {
    console.log("信息");
  }
};

Reflect.defineMetadata("key1", "我是一个对象的元数据", obj);
console.log(Reflect.hasMetadata("key1", obj));
console.log(Reflect.getMetadata("key1", obj));

Reflect.defineMetadata("usernamemetakey", "用户名合法", obj, "username");
console.log(Reflect.getMetadata("usernamemetakey", obj, "username"));

console.log("-------------------------------------------");

@Reflect.metadata("decribe", "都是地球人")
class People {
  @Reflect.metadata("descible", "姓名不能包含非法汉字")
  username = "wukong";

  @Reflect.metadata("importinfo", "吃烤鸭")
  eat() {}
}

console.log(Reflect.getMetadata("decribe", People));
console.log(Reflect.getMetadata("descible", People.prototype, "username"));
console.log(Reflect.getMetadata("importinfo", People.prototype, "eat"));

class ChinesePeople extends People {}

console.log(Reflect.getMetadata("decribe", ChinesePeople));
console.log(
  Reflect.getMetadata("descible", ChinesePeople.prototype, "username")
);
console.log(Reflect.getMetadata("importinfo", ChinesePeople.prototype, "eat"));
console.log(Reflect.hasMetadata("importinfo", ChinesePeople.prototype, "eat")); // true
console.log(
  Reflect.hasOwnMetadata("importinfo", ChinesePeople.prototype, "eat")
); // false
